﻿/*
 * Twipler - Twitter Web Client with features.
 *  
 *  Copyright (C) 2009, 2010. Ian Quigley
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details. 
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Twipler.App.Render.Tree;
using Twipler.App.Parse.Code;

namespace Twipler.App.Parse.Html.Consumers
{
    [Consumer(OpenTag="variable")]
    public class VariableConsumer : TemplateConsumer
    {
  
        public override App.Render.Tree.AbstractItem Process(Template template, TemplateConsumer parent)
        {
            string name = string.Empty;
            int index = template.Find(Template.EndMarker);
            if (index == -1)
                return Error(template, "Missing " + Template.EndMarker + " from Variable");

            name = template.ConsumeUpTo(index).Trim();
            if (string.IsNullOrEmpty(name))
                return Error(template, "Missing variable name");

            template.SkipOver(Template.EndMarker);
            return App.Render.Tree.VariableItem.Create(name.Trim());
        }
    }
}